package com.example.juc.big_talk_concurrent.chapter1.article6;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Client {

     static class MyCallable implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            return 100;
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable callable = new MyCallable();
        FutureTask<Integer> task = new FutureTask<>(callable); // 妥妥适配器模式，目的就是为了将callable接口转为runnable接口再传进Thread类去执行任务，包装+转换
        Thread thread = new Thread(task);
        thread.start();

        Integer res = task.get(); //get是阻塞方法，阻塞调用线程向下的执行
        System.out.println(res);
    }

}
